package org.sample.springbootactivemq.config;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;

@Configuration
@EnableJms
public class MessageReceiverConfig {

	@Value("${activemq.broker-url}")
	private String brokerUrl;

	@Bean
	public ActiveMQConnectionFactory activeMQConnectionFactory() {

		ActiveMQConnectionFactory activeMQConnectionFactory =
				new ActiveMQConnectionFactory();

		activeMQConnectionFactory.setBrokerURL(brokerUrl);

		return activeMQConnectionFactory;
	}

	@Bean
	public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
			@Autowired ActiveMQConnectionFactory activeMQConnectionFactory) {

		DefaultJmsListenerContainerFactory jmsListenerContainerFactory =
				new DefaultJmsListenerContainerFactory();

		jmsListenerContainerFactory.setConnectionFactory(activeMQConnectionFactory);

		return jmsListenerContainerFactory;
	}

}
